# -*- coding: utf-8 -*-
from PyQt5 import QtWidgets
from gui.data_analysis.condition_setting import Ui_Dialog
from PyQt5.QtGui import QIcon,QPixmap
from PyQt5.QtCore import pyqtSignal,pyqtSlot
from PyQt5.QtWidgets import QDialog,QMessageBox


class ConditionWindow(QtWidgets.QDialog, Ui_Dialog):
    dialogSignal = pyqtSignal(object, object, object)

    def __init__(self):
        super().__init__()
        self.setupUi(self)
        icon = QIcon()
        icon.addPixmap(
            QPixmap("icons/logo.ico"),
            QIcon.Normal,
            QIcon.Off)
        self.setWindowIcon(icon)

    def set_para_2_widget(self, test_para):
        self.cbb_para.clear()
        self.cbb_para.addItems(test_para)

    @pyqtSlot()
    def on_btnEnsure_clicked(self):
        test_para = self.cbb_para.currentText().strip()
        con_start = self.le_start.text().strip()
        con_end = self.le_end.text().strip()
        if con_start and con_end:
            self.dialogSignal.emit(test_para, con_start, con_end)
            self.close()
        else:
            self.show_notification("提示", "查询条件不能为空")

    def show_notification(self, title, content):
        QMessageBox.information(self, title, content, QMessageBox.Yes, QMessageBox.Yes)

    @pyqtSlot()
    def on_btnCancel_clicked(self):
        self.close()
